a11y: Don't present HIDDEN accessibles
authorMatthias Clasen <mclasen@redhat.com>
Sat, 24 Oct 2020 14:32:24 +0000 (10:32 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 24 Oct 2020 15:17:56 +0000 (11:17 -0400)
The ARIA spec is clear on this: when an element has the
HIDDEN state, it should not be presented in the accessible
tree.

This change is incomplete, we also need to emit child-added/
removed signals when the state changes, but that needs to
wait for the child added infrastructure to land.

gtk/gtkaccessible.c

index 49fea56fb667a27bbb05dca4993c5569f497f643..12be6332a3427373706b68b3726e88b38c5836fe 100644 (file)
@@ -742,6 +742,8 @@ gtk_accessible_bounds_changed (GtkAccessible *self)
 gboolean
 gtk_accessible_should_present (GtkAccessible *self)
 {
+  GtkATContext *context;
+
   if (GTK_IS_WIDGET (self) &&
       !gtk_widget_get_visible (GTK_WIDGET (self)))
     return FALSE;
@@ -749,6 +751,16 @@ gtk_accessible_should_present (GtkAccessible *self)
   if (gtk_accessible_get_accessible_role (self) == GTK_ACCESSIBLE_ROLE_NONE)
     return FALSE;
 
+  context = gtk_accessible_get_at_context (self);
+  if (gtk_at_context_has_accessible_state (context, GTK_ACCESSIBLE_STATE_HIDDEN))
+    {
+      GtkAccessibleValue *value;
+
+      value = gtk_at_context_get_accessible_state (context, GTK_ACCESSIBLE_STATE_HIDDEN);
+      if (gtk_boolean_accessible_value_get (value))
+        return FALSE;
+    }
+
   return TRUE;
 }